//
//  CCLoginViewModel.m
//  Activity
//
//  Created by coco on 15/5/9.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCLoginViewModel.h"
#import <AVOSCloud/AVOSCloud.h>
#import "CCError.h"
@implementation CCLoginViewModel

- (id) init {
  if ( self = [super init]) {
    _title = @"用户账户登录";
  }
  return self;
}

- (RACSignal *)login {
  return  [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [AVUser logInWithMobilePhoneNumberInBackground:self.user password:self.password block:^(AVUser *user, NSError *error) {
      if (user) {
        [subscriber sendNext: ERROR(5000)];
      } else if (error.code == -1009) {
          [subscriber sendNext:ERROR(1000)];
      } else {
        [subscriber sendNext:ERROR(5001)];
      }
      [subscriber sendCompleted];
    }];
    return [RACDisposable disposableWithBlock:^{
      [subscriber sendCompleted];
    }];
  }];
}
@end
